package com.sun.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sun.pojo.PmsProduct;
import com.sun.pojo.PmsProductCategory;
import com.sun.mapper.PmsProductCategoryMapper;
import com.sun.service.IPmsProductCategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 产品分类 服务实现类
 * </p>
 *
 * @author 妙妙屋
 * @since 2021-12-27
 */
@Service
public class PmsProductCategoryServiceImpl extends ServiceImpl<PmsProductCategoryMapper, PmsProductCategory> implements IPmsProductCategoryService {
    @Autowired
    private PmsProductCategoryMapper pmsProductCategoryMapper;
    @Override
    public List<PmsProductCategory> listChildren() {
        return pmsProductCategoryMapper.listChildren();
    }

    @Override
    public Page<PmsProductCategory> list(Long parentId, String pageSize, String pageNum) {
        Page<PmsProductCategory> page = new Page<PmsProductCategory>(Long.parseLong(pageNum),Long.parseLong(pageSize));
        QueryWrapper<PmsProductCategory> qr = new QueryWrapper<>();
        qr.eq("parent_id",parentId);
        Page<PmsProductCategory> p = pmsProductCategoryMapper.selectPage(page, qr);
        return p;
    }

    @Override
    public void addRelation(Long id, Long id1) {
            Map map = new HashMap();
        map.put("pcid",id);
        map.put("paid",id1);
        pmsProductCategoryMapper.addRelation(map);
    }
}
